package com.shawn.integeration.common.model.res;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * 通用返回对象
 *
 * @author: shawn
 * @Date: 2023/12/27 09:47
 * @Version 1.0.0
 */
@Getter
@Setter
public class GenericResponse<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    private Integer code;

    private String msg;

    private T data;

    private GenericResponse(){}

    private GenericResponse(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> GenericResponse<T> success(T data) {
        return new GenericResponse(0,"成功",data);
    }

    public static <T> GenericResponse<T> success() {
        return new GenericResponse(0,"操作",null);
    }

    public static <T> GenericResponse<T> error() {
        return new GenericResponse(1,"操作失败",null);
    }

    public static <T> GenericResponse<T> error(String msg) {
        return new GenericResponse<>(1,msg,null);
    }
}
